<template>
  <PermissionContainer
    :jiBieArr="[0, 1, 2]"
    :tipArr="[
      ,
      '电子卡功能只对集团和站点级别开放',
      '因为集团上关于电子卡的共享配置，此级没有配置权限',
      ,
      '您暂未启动电子卡功能',
    ]"
  >
    <div class="app-container">
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="120px"
      >
        <!-- <el-form-item label="会员名" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
        <el-form-item label="手机号" prop="mobliePhone">
          <el-input
            v-model="queryParams.mobilePhone"
            placeholder="请输入客户手机号"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="电子卡类型" prop="cardOilsType">
          <el-select
            v-model="queryParams.cardOilsType"
            placeholder="请选择电子卡类型"
            clearable
            size="small"
          >
            <el-option label="汽油卡" value="1"></el-option>
            <el-option label="柴油卡" value="2"></el-option>
            <!-- <el-option label="非油品卡" value="3"></el-option> -->
            <el-option label="LNG卡" value="3"></el-option>
            <el-option label="CNG卡" value="4"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="充值消费类型" prop="usageType">
          <el-select
            v-model="queryParams.usageType"
            placeholder="请选择消费充值类型"
            clearable
            size="small"
          >
            <el-option label="充值" value="+" />
            <el-option label="消费" value="-" />
          </el-select>
        </el-form-item>
        <el-form-item label="充值方式" prop="payType">
          <el-select
            v-model="queryParams.payType"
            placeholder="请选择充值方式"
            clearable
            size="small"
          >
            <el-option label="导入" value="imp" />
            <el-option label="微信" value="wx" />
          </el-select>
        </el-form-item>
        <el-form-item label="支付时间">
          <el-date-picker
            v-model="dateRangeCreatedDate"
            type="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            size="mini"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-form
        :model="sumCard"
        ref="sumCard"
        :inline="true"
        label-width="128px"
      >
        <!-- <el-form-item label="会员名" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
        <el-form-item label="汽油卡总余额" prop="qyAmt">
          <div style="font-size: 1.5vw">{{ sumCard.qyAmt || 0 }}元</div>
        </el-form-item>
        <el-form-item label="柴油卡总余额" prop="cyAmt">
          <div style="font-size: 1.5vw">{{ sumCard.cyAmt || 0 }}元</div>
        </el-form-item>
        <el-form-item label="LNG总余额" prop="LNGAmt">
          <div style="font-size: 1.5vw">{{ sumCard.lngamt || 0 }}元</div>
        </el-form-item>
        <el-form-item label="CNG总余额" prop="CNGAmt">
          <div style="font-size: 1.5vw">{{ sumCard.cngamt || 0 }}元</div>
        </el-form-item>
      </el-form>
      <el-table :data="recordList">
        <af-table-column label="id" align="left" prop="id" v-if="false" />
        <af-table-column label="油站名" align="left" prop="stationName" />
        <af-table-column label="充值/消费单号" align="left" prop="orderNo" />
        <!-- <af-table-column label="会员号ID" align="left" prop="customerNo" /> -->
        <af-table-column label="客户名" align="left" prop="customerName" />
        <af-table-column
          label="消费充值类型"
          align="left"
          prop="usageType"
          :formatter="usageTypeFotmat"
        />
        <af-table-column
          label="充值方式"
          align="left"
          prop="payType"
          :formatter="payTypeFotmat"
        />
        <af-table-column
          label="油品"
          align="left"
          prop="cardOilsType"
          :formatter="cardOilsTypeFotmat"
        />
        <af-table-column label="充值、消费金额(元)" align="left" prop="amt" />
        <af-table-column label="赠送金额(元)" align="left" prop="presentAmt" />
        <af-table-column label="消费后余额(元)" align="left" prop="balance" />
        <af-table-column label="手机号" align="left" prop="mobilePhone" />
        <af-table-column
          label="充值、消费时间"
          align="left"
          prop="createTime"
        />
        <af-table-column
          label="油站ID"
          align="left"
          prop="stationId"
          v-if="false"
        />
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </PermissionContainer>
</template>

<script>
import { listRecord } from "@/api/customer/record";
import { cardUserSum } from "@/api/customer/card";

export default {
  name: "Dzk_Bill",
  data() {
    return {
      // 总条数
      total: 0,
      // 客户电子会员卡充值消费记录表格数据
      recordList: [],
      sumCard: {
        qyAmt: null,
        cyAmt: null,
        lngamt: null,
        cngamt: null,
      },
      //查询日期
      dateRangeCreatedDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        customerNo: null,
        customerName: null,
        usageType: null,
        payType: null,
        cardOilsType: null,
        mobilePhone: null,
        levelId: this.levelId,
      },
    };
  },
  created() {
    this.getList();
    this.getCardSum();
  },
  methods: {
    usageTypeFotmat(row, column) {
      if (row.usageType === "+") {
        return "充值";
      } else if (row.usageType === "-") {
        return "消费";
      }
    },
    cardOilsTypeFotmat(row, column) {
      if (row.cardOilsType === "1") {
        return "汽油";
      } else if (row.cardOilsType === "2") {
        return "柴油";
      } else if (row.cardOilsType === "3") {
        return "LNG";
      } else if (row.cardOilsType === "4") {
        return "CNG";
      }
    },
    payTypeFotmat(row, column) {
      if (row.payType === "wx") {
        return "微信";
      } else if (row.payType === "imp") {
        return "导入";
      }
      return "----";
    },
    /** 查询客户电子会员卡充值消费记录列表 */
    getList() {
      this.queryParams.levelId = this.levelId;
      listRecord(
        this.addDateRange(this.queryParams, this.dateRangeCreatedDate)
      ).then((response) => {
        this.recordList = response.rows;
        this.total = response.total;
      });
    },
    /** 分类统计电子卡的余额*/
    getCardSum() {
      this.queryParams.levelId = this.levelId;
      cardUserSum(
        this.addDateRange(this.queryParams, this.dateRangeCreatedDate)
      ).then((response) => {
        this.sumCard = response.data;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getCardSum();
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
